/*Copyright (C) 2009 - 2011 MASSART GAUTHIER

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "../headers.h"

void morp_afficher_symbole(char matrice[10]) {
	short x = 0, y = 0, test = 1;
	bool ok = false, croix = false;

	while(test != 10) {
		ok = false;

		if(matrice[test] == 'O') {
			ok = true;
			croix = false;
		}
		if(matrice[test] == 'X') {
			ok = true;
			croix = true;
		}

		if(test == 9) {
			y = 7;
			x = x_begin_center(46) + 34;
		}

		if(test == 8) {
			y = 7;
			x = x_begin_center(46) + 19;
		}

		if(test == 7) {
			y = 7;
			x = x_begin_center(46) + 4;
		}

		if(test == 6) {
			y = 15;
			x = x_begin_center(46) + 34;
		}

		if(test == 5) {
			y = 15;
			x = x_begin_center(46) + 19;
		}

		if(test == 4) {
			y = 15;
			x = x_begin_center(46) + 4;
		}

		if(test == 3) {
			y = 23;
			x = x_begin_center(46) + 34;
		}

		if(test == 2) {
			y = 23;
			x = x_begin_center(46) + 19;
		}

		if(test == 1) {
			y = 23;
			x = x_begin_center(46) + 4;
		}

		if(ok) {
			if(croix) {
				CSLP_ColorText(COLOR_RED);
				mvaddstr(y    , x, "X      X");
				mvaddstr(y + 1, x, " X    X ");
				mvaddstr(y + 2, x, "   XX   ");
				mvaddstr(y + 3, x, " X    X ");
				mvaddstr(y + 4, x, "X      X");
			}
			else {
				CSLP_ColorText(COLOR_CYAN);
				mvaddstr(y    , x, "  OOOO  ");
				mvaddstr(y + 1, x, " O    O ");
				mvaddstr(y + 2, x, "O      O");
				mvaddstr(y + 3, x, " O    O ");
				mvaddstr(y + 4, x, "  OOOO  ");
			}
		}

		test++;
	}
}

void morp_affichage_fond(char matrice[10]) {
	short y = 5, x = x_begin_center(46), i = 0, j = 0;

	CSLP_ColorText(COLOR_WHITE);

	while(i != 3) {
		move(y, x);
		afficher_char_fullblock(46, COLOR_WHITE);
		y++;

		while(j != 7) {
			move(y, x);
			afficher_char_fullblock(1, COLOR_WHITE);
			addstr("             ");
			if(j == 6) {
				printw("%ld", 7 - 3 * i);
			}
			else {
				addstr(" ");
			}
			afficher_char_fullblock(1, COLOR_WHITE);
			addstr("             ");
			if(j == 6) {
				printw("%ld", 8 - 3 * i);
			}
			else {
				addstr(" ");
			}
			afficher_char_fullblock(1, COLOR_WHITE);
			addstr("             ");
			if(j == 6) {
				printw("%ld", 9 - 3 * i);
			}
			else {
				addstr(" ");
			}
			afficher_char_fullblock(1, COLOR_WHITE);
			y++;
			j++;
		}

		i++;
		j = 0;
	}

	move(y, x);
	afficher_char_fullblock(46, COLOR_WHITE);
	morp_afficher_symbole(matrice);
	refresh();
}
